import { createVNode, render } from 'vue'

/**
 * 动态LoadDialog调用
 */
export default options => {
  const LoadDialog = defineAsyncComponent(() => import('../components/LoadDialog.vue'))

  let el = document.createElement('div')

  const vm = createVNode(LoadDialog, {
    ...options,
    component: options.component.name,
    props: options.component.props,
    modelValue: true,
    onClose: () => {
      destroy()
    },
  })

  const destroy = () => {
    document.body.removeChild(el)
    el = null
  }

  render(vm, el)
  document.body.appendChild(el)
}
